package com.bawei.liuzhanlin20210719.view.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bawei.liuzhanlin20210719.R;
import com.bawei.liuzhanlin20210719.model.bean.MovieBean;
import com.bawei.liuzhanlin20210719.model.utils.HttpUtils;
import com.bawei.liuzhanlin20210719.view.adapter.MovieAdapter;
import com.bawei.liuzhanlin20210719.view.weight.BiaoTi;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.bt)
    BiaoTi bt;
    @BindView(R.id.rlv)
    RecyclerView rlv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        //获取输入框的值
        String s = bt.getEtNr().getText().toString();
        Log.d("123",s);
        //展示数据
        HttpUtils.getInstance().getApiService().movieservice(s,1,5)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<MovieBean>() {
                    @Override
                    public void accept(MovieBean movieBean) throws Exception {
                        //点击搜索
                        bt.getTvSs().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                rlv.setLayoutManager(new LinearLayoutManager(MainActivity.this));
                                rlv.setAdapter(new MovieAdapter(movieBean.result,MainActivity.this));
                            }
                        });
                    }
                });
    }
}
